<?php

namespace App\Admin\Metrics\Home;

use App\Models\GroupBuying\GoOrder as GoOrderAlias;
use App\Models\Reservation as ReservationModel;
use App\Models\User;
use App\Services\Tenancy\TenancyService;
use Dcat\Admin\Widgets\Metrics\Card;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;


class Reservation extends Card
{
    /**
     * 卡片底部内容.
     *
     * @var string|Renderable|\Closure
     */
    protected $footer;

    /**
     * 初始化卡片.
     */
    protected function init()
    {
        parent::init();
        $this->title('<span style="color:#487BFF;">抢拍预约</span>');
    }

    public function style(string $style)
    {
        return parent::style($style); // TODO: Change the autogenerated stub
    }

    /**
     * 处理请求.
     *
     * @param Request $request
     *
     * @return void
     */
    public function handle(Request $request)
    {
        $this->content(User::query()->count());
//        $this->up(15);
    }

    /**
     * @param int $percent
     *
     * @return $this
     */
    public function up($percent)
    {
        return $this->footer(
            "<i class=\"feather icon-trending-up text-success\"></i> {$percent}% Increase"
        );
    }

    /**
     * @param int $percent
     *
     * @return $this
     */
    public function down($percent)
    {
        return $this->footer(
            "<i class=\"feather icon-trending-down text-danger\"></i> {$percent}% Decrease"
        );
    }

    /**
     * 设置卡片底部内容.
     *
     * @param string|Renderable|\Closure $footer
     *
     * @return $this
     */
    public function footer($footer)
    {
        $this->footer = $footer;

        return $this;
    }

    public function setUpChartMargin()
    {
        parent::setUpChartMargin(); // TODO: Change the autogenerated stub
//        $this->chart->style("background: linear-gradient(180deg, #DFEEFF 0%, #FFF 100%);");
    }

    /**
     * 渲染卡片内容.
     *
     * @return string
     */
    public function renderContent()
    {
        $count = ReservationModel::query()->count();
        $count_waiting = ReservationModel::query()
            ->where('cur_status',ReservationModel::ORDER_WAITING)
            ->count();
        $orderCount = GoOrderAlias::query()->where('is_complain', 1)->whereNull('run_complain_time')->count();

        return <<<HTML
<div class="row text-center" style="margin-bottom: 150px">
<div class="col-sm-6 ">
<p style="font-size: 50px;">{$count}</p>
<p style="font-size: 14px;">预约总数</p>
</div>
<div class="col-sm-6">
<p style="font-size: 50px;">{$count_waiting}</p>
<p style="font-size: 14px;">待处理预约</p>
</div>

<div class="col-sm-10 offset-1">
<a class=" btn btn-outline-success btn-block" href="/boss1688/reservation">查看预约</a>
</div>
<div class="col-sm-10 offset-1">
<hr style="color:red;width: 100%"/>
</div>
<div class="col-sm-6 ">
<p style="font-size: 50px;">{$orderCount}</p>
<p style="font-size: 14px;">申诉订单数量</p>
</div>
<div class="col-sm-10 offset-1">
<a class=" btn btn-outline-success btn-block" href="/boss1688/go-order">查看订单</a>
</div>
</div>
HTML;
    }

    /**
     * 渲染卡片底部内容.
     *
     * @return string
     */
    public function renderFooter()
    {
        return $this->toString($this->footer);
    }
}
